package com.liwq.cloudstudygateway.config;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author : liwq
 * @version : 1.0
 * @date : 2022/7/5
 **/
@Component
public class HelloFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //获取请求对象
        ServerHttpRequest request = exchange.getRequest();
        //获取请求的ip地址
        System.out.println("全局过滤器HelloFilter执行了,IP:"+request.getRemoteAddress().getHostString());
        return chain.filter(exchange);//放行
    }
}
